import sympy as sp

def comprehensive_derivative_practice():
    x = sp.Symbol('x')
    
    print("=== 复杂函数求导实战 ===")
    print("以下函数结合了多种运算和复合关系：\n")
    
    # 复杂函数示例
    complex_functions = [
        ("乘积与三角函数复合", x**2 * sp.sin(3*x), "乘法法则 + 链式法则"),
        ("指数函数与对数函数复合", sp.exp(sp.log(x**2 + 1)), "链式法则"),
        ("商式与三角函数结合", sp.tan(x) / (1 + x**2), "除法法则 + 三角函数求导"),
        ("多层复合函数", sp.sin(sp.cos(sp.sqrt(x))), "多层链式法则"),
        ("反三角函数与多项式", x * sp.asin(x), "乘法法则 + 反函数求导")
    ]
    
    for name, func, technique in complex_functions:
        print(f"{name}:")
        print(f"  函数: f(x) = {func}")
        print(f"  求导技术: {technique}")
        
        # 求导
        derivative = sp.diff(func, x)
        derivative_simplified = sp.simplify(derivative)
        
        print(f"  求导结果: f'(x) = {derivative_simplified}")
        print()
    
    return complex_functions

def real_world_application():
    print("=== 实际应用案例：净化费用变化率 ===")
    
    # 基于[1](@ref)中的净化费用例子
    x = sp.Symbol('x')  # x表示纯净度百分比
    
    # 净化到纯净度为x%时所需费用
    purification_cost = 10000 / (100 - x)  # 单位：元/吨
    
    print("问题：计算水净化到不同纯净度时费用的瞬时变化率")
    print(f"净化费用函数: c(x) = {purification_cost} (x为纯净度百分比)\n")
    
    # 求导得到瞬时变化率
    cost_derivative = sp.diff(purification_cost, x)
    print(f"费用变化率函数: c'(x) = {cost_derivative}")
    
    # 计算特定纯净度下的变化率
    purities = [90, 95, 98]  # 纯净度百分比
    
    for purity in purities:
        rate = cost_derivative.subs(x, purity)
        print(f"纯净度 {purity}% 时的费用变化率: {rate:.2f} 元/吨每百分比")
    
    print("\n结论：纯净度越高，净化费用增加的速度越快！")

# 运行实战练习
print("复杂函数求导练习：")
practice_results = comprehensive_derivative_practice()

print("\n" + "="*60 + "\n")
real_world_application()